package cn.kinggm520.service;

import cn.kinggm520.mapper.UserMapper;
import cn.kinggm520.pojo.User;
import com.alibaba.fastjson.JSON;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class UserService1 {

    @Resource
    private UserMapper userMapper;

    public String search(){
        List<User> all = userMapper.findAll();
        return JSON.toJSONString(all);
    }

    @Transactional(propagation = Propagation.NESTED)
    public void b(){
        User user = new User();
        user.setId(3);
        user.setUserName("四眼1");
        user.setPassword("123123");
        user.setBirthday(new Date());
        userMapper.insert(user);
    }




    @Transactional(propagation = Propagation.REQUIRED)
    public void c(){
        User user = new User();
        user.setId(4);
        user.setUserName("四眼1");
        user.setPassword("123123");
        user.setBirthday(new Date());
        userMapper.insert(user);
    }




}
